package com.ogawa.chair7808.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.ogawa.base.Constant.CommmandNum;
import com.ogawa.base.utils.CommonUtil;
import com.ogawa.chair7808.R;
import com.ogawa.chair7808.manager.DataManager;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by FHB on 2018/4/24.
 */
public class LayoutGears5_7808 extends RelativeLayout implements View.OnClickListener {
    private List<ImageView> mIvLists = new ArrayList<>();
    private ImageView mIvSub ;
    private ImageView mIvAdd;
    private int mType;
    private Context mContext;
    public LayoutGears5_7808(Context context) {
        super(context);
        mContext = context;
    }

    public LayoutGears5_7808(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mIvLists.clear();
        mIvLists.add((ImageView) findViewById(R.id.iv_gears5_0));
        mIvLists.add((ImageView) findViewById(R.id.iv_gears5_1));
        mIvLists.add((ImageView) findViewById(R.id.iv_gears5_2));
        mIvLists.add((ImageView) findViewById(R.id.iv_gears5_3));
        mIvLists.add((ImageView) findViewById(R.id.iv_gears5_4));
        mIvLists.add((ImageView) findViewById(R.id.iv_gears5_5));
        mIvSub = findViewById(R.id.iv_gears5_sub);
        mIvAdd =  findViewById(R.id.iv_gears5_add);
        mIvSub.setOnClickListener(this);
        mIvAdd.setOnClickListener(this);
    }
    public  void setShow(int position){
        for(int i =0;i<mIvLists.size();i++){
            if(i==position){
                mIvLists.get(i).setVisibility(VISIBLE);
            }
            else {
                mIvLists.get(i).setVisibility(GONE);
            }
        }
    }

    /**
     *
     * @param type 1：3d  2 力度 3 速度    4 充气强度
     */
    public void setType(int type){
        mType =type;

    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.iv_gears5_sub) {
            if (CommonUtil.isFastClick()) {
                return;
            } else {
                if(mType==1){
                    DataManager.getDataManager().sendCommond(CommmandNum.JIX3DSUB,"0");
                }
                else if(mType==2){
                    DataManager.getDataManager().sendCommond(CommmandNum.LIDUSUB,"0");
                }
                else if(mType ==3){
                    DataManager.getDataManager().sendCommond(CommmandNum.SUDUSUB,"0");
                }
                else if(mType ==4){
                    DataManager.getDataManager().sendCommond(CommmandNum.CONGQIQDSUB,"0");
                }

            }

        }
        else if (i == R.id.iv_gears5_add) {
            if (CommonUtil.isFastClick()) {
                return;
            } else {
                if(mType==1){
                    DataManager.getDataManager().sendCommond(CommmandNum.JIX3DADD,"1");
                }
                else if(mType==2){
                    DataManager.getDataManager().sendCommond(CommmandNum.LIDUADD,"1");
                }
                else if(mType ==3){
                    DataManager.getDataManager().sendCommond(CommmandNum.SUDUADD,"1");
                }
                else if(mType ==4){
                    DataManager.getDataManager().sendCommond(CommmandNum.CONGQIQDADD,"1");
                }


            }


        }

    }
}
